package leetcode;

import util.Tree;
import util.TreeNode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0513.java
 * @Author : WangRuoyu
 * @Date 2023/10/23 12:31
 */

public class Q0513 {
    int lavel = 0;
    int res = 0;

    private void dfs(TreeNode root, int k) {
        if (root == null) {
            return;
        }
        if (k > lavel) {
            lavel = k;
            res = root.val;
        }
        dfs(root.left, k + 1);
        dfs(root.right, k + 1);
    }

    public int findBottomLeftValue(TreeNode root) {
        dfs(root, 1);
        return res;
    }

    public static void main(String[] args) {
        Q0513 sl = new Q0513();
        String[] tree = {"0", null, null};
        TreeNode root = Tree.createTreeByPreorder(tree);
//        Tree.traversal(root);
        System.out.println(sl.findBottomLeftValue(root));
    }
}